<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta charset="utf-8">
  <title>自动点名修改</title>
  <base href="<%=basePath%>">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" type="text/css" href="style/easyui/easyui.css">
</head>
<body>
  <div class="layui-form" lay-filter="layuiadmin-quartzJob-form-list" id="layuiadmin-quartzJob-form-list" style="padding: 20px 30px 0 0;">
    <input type="hidden" name="id" id="id" value="${quartzjob.quartzjob.id}"/>
     <div class="layui-form-item">
      <label class="layui-form-label" style="width: 20%">时间设定：</label>
      <div class="layui-input-inline" style="width: 100px;">
      	 <select name="hour" id="hour" lay-filter="expressiontime" lay-verify="required">
          <option value="">小时</option><option value="0">0</option>
          <option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
          <option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>
          <option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
          <option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option>
          <option value="21">21</option><option value="22">22</option><option value="23">23</option>
         </select>
      </div>
      <label class="layui-form-label" style="text-align: left;; width: 20px;">时：</label> 
      
      <div class="layui-input-inline" style="width: 100px;">
      	 <select name="minute" id="minute" lay-filter="expressiontime" lay-verify="required">
          <option value="">分钟</option><option value="0">0</option>
          <option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
          <option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>
          <option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option>
          <option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option>
          <option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option>
          <option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option>
          <option value="31">31</option><option value="32">32</option><option value="33">33</option><option value="34">34</option><option value="35">35</option>
          <option value="36">36</option><option value="37">37</option><option value="38">38</option><option value="39">39</option><option value="40">40</option>
          <option value="41">41</option><option value="42">42</option><option value="43">43</option><option value="44">44</option><option value="45">45</option>
          <option value="46">46</option><option value="47">47</option><option value="48">48</option><option value="49">49</option><option value="50">50</option>
          <option value="51">51</option><option value="52">52</option><option value="53">53</option><option value="54">54</option><option value="55">55</option>
          <option value="56">56</option><option value="57">57</option><option value="58">58</option><option value="59">59</option>
         </select>
      </div>
      <label class="layui-form-label" style="text-align: left;; width: 10px;">分：</label>      
    </div>
    
    <div class="layui-form-item" >
	    <label class="layui-form-label" style="width: 20%">选择星期几：</label>
	    <div class="layui-input-block" style="width: 80%">
	        <!--下面的hidden用来提交复选框值用的，解决layui复选框提交到后台只有一个值的BUG-->
	        <input type="hidden" name="weekcodes" id="weekcodes"/>
	        <c:forEach  var="demo" items="${weeklist}" varStatus="status">
	           <input type="checkbox" name="weekcode" lay-skin="primary" lay-filter="expressiontime" title="${demo.weekname}" value="${demo.weekcode}" <c:if test="${demo.pageSelected}">checked</c:if> <c:if test="${demo.pageUsed}">disabled</c:if>>
	        </c:forEach>
	    </div>
	</div>
    
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 20%">规则说明：</label>
      <div class="layui-input-inline" style="width: 60%">
        <input type="text" name="expressiontimename" id="expressiontimename"  class="layui-input" readonly = "readonly" value="${quartzjob.quartzjob.cronexpressionname}">
      </div>
    </div>
    
    
    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="layuiadmin-quartzJob-form-submit" id="layuiadmin-quartzJob-form-submit" value="确认添加">
      <input type="button" lay-submit lay-filter="layuiadmin-quartzJob-form-edit" id="layuiadmin-quartzJob-form-edit" value="确认编辑">
    </div>
  </div>

  <script src="layuiadmin/layui/layui.js"></script>  
  <script src="layuiadmin/js/common/jquery.js"></script>
  <script src="layuiadmin/js/common/jquery.easyui.min.js"></script>
  <script src="layuiadmin/js/form.js"></script>
  <script>
 	layui.config({
	    base: 'layuiadmin/' //静态资源所在路径
	  }).extend({
	    index: 'lib/index' //主入口模块
	  }).use(['index', 'form', 'laydate'], function(){
		  var $ = layui.$
		    ,admin = layui.admin
		    ,element = layui.element
		    ,layer = layui.layer
		    ,laydate = layui.laydate
		    ,form = layui.form;
	    
	    //监听提交
	    form.on('submit(layuiadmin-quartzJob-form-submit)', function(obj){
	      	var field = obj.field; //获取提交的字段
	      	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
	
	      	//提交 Ajax 成功后，关闭当前弹层并重载表格
	      	//$.ajax({});
	      

	      	var chk_value =[]; 
	        $('input[name="weekcode"]:checked').each(function(){ 
	        	chk_value.push($(this).val()); 
	        });
	      	
	        if(chk_value.length > 0){
	        	field.weekcodes = chk_value.join(',');//将数组合并成字符串
		      	layer.confirm('确定操作?', function(index){
		      		
		      		layer.msg('正在提交请稍候。。。', {icon: 16,time:'-1',shade : [0.5 , '#000' , true]});
		      		
		      		admin.req({
		    		    url: 'quartzJob/update' //实际使用请改成服务端真实接口
		    	        ,data: field
		    	        ,type: 'POST'
		    	        ,done: function(res){
		    	        	layer.msg(res.msg);
		    	        }
		         	});
		        });
	        }else{
	        	layer.msg("请先选择星期几");
	        	return false;
	        }
	        //parent.layer.close(index); //再执行关闭 
	    });
	    
	    form.on('select(expressiontime)', function(data){
	    	  var hour = document.getElementById('hour').value;
	    	  var minute = document.getElementById('minute').value;
	    	  
	    	  var expressiontimename_week = ""; 
		      $('input[name="weekcode"]:checked').each(function(){ 
		    	  var weekcode = $(this).attr("title")
		    	  expressiontimename_week = expressiontimename_week + weekcode + " ";
		      });
	    	  
	    	  var expressiontimename = expressiontimename_week + hour + "点" + minute +"分 执行一次"
	    	  
	    	  document.getElementById('expressiontimename').value = expressiontimename;
	    	  
	    });
	    
	    form.on('checkbox(expressiontime)', function(data){
	    	  var hour = document.getElementById('hour').value;
	    	  var minute = document.getElementById('minute').value;
	    	  
	    	  var expressiontimename_week = ""; 
		      $('input[name="weekcode"]:checked').each(function(){ 
		    	  var weekcode = $(this).attr("title")
		    	  expressiontimename_week = expressiontimename_week + weekcode + " ";
		      });
	    	  
	    	  
	    	  var expressiontimename = expressiontimename_week + hour + "点" + minute +"分 执行一次"
	    	  
	    	  document.getElementById('expressiontimename').value = expressiontimename;
	    	  
	    });
    	
	    var hour = '${quartzjob.quartzjob.hour}';
	    var minute = '${quartzjob.quartzjob.minute}';
	    
	    form.render('select','#expressiontime');
	    
    	$("#hour").val(hour); //直接赋值
    	$("#minute").val(minute); //直接赋值
	    
    	form.render(); //更新全部
    	
	  })
	 
	  
  </script>
</body>
</html>